<%--
  Created by IntelliJ IDEA.
  User: 王一同
  Date: 2021/11/20
  Time: 12:45
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>修改密码</title>
</head>
<link rel="stylesheet" href="${pageContext.request.contextPath}/layui/css/layui.css"/>
<script src="${pageContext.request.contextPath}/layui/layui.js"></script>
<body style="position: absolute ; width: 100%;height: 100%;">
<div style="font-size:24px;color: cadetblue;font-weight: bolder;position: relative;left: 27%;top: 136px;width: 100px;height: 30px;">
    密码修改
</div>
    <form class="layui-form"  style="margin: 190px 437px;font-size: 17px;" id="form" >
            <div class="layui-form-item">
                <label class="layui-form-label" style="width: 120px">旧密码：</label>
            <div class="layui-input-inline">
                <input type="password" name="e_password" id="e_password" lay-verify="pass" placeholder="请输入旧密码"
                       autocomplete="off"
                       class="layui-input">
            </div>
            <div style="display: none" class="layui-form-mid layui-word-aux">请填写6到12位密码</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" style="width: 120px">新密码：</label>
            <div class="layui-input-inline">
                <input type="password" name="new_password" id="new_password" lay-verify="pass" placeholder="请输入新密码"
                       autocomplete="off"
                       class="layui-input">
            </div>
            <div style="display: none" class="layui-form-mid layui-word-aux">请填写6到12位密码</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label" style="width: 120px">请确认新密码：</label>
            <div class="layui-input-inline">
                <input type="password" name="again_password" id="again_password" lay-verify="pass" placeholder="请再次输入密码"
                       autocomplete="off"
                       class="layui-input">
            </div>
            <div style="display: none" class="layui-form-mid layui-word-aux">请填写6到12位密码</div>
        </div>
        <div class="layui-form-item" style="text-align: center">
            <button class="layui-btn" type="button" lay-submit lay-filter="formDemo" id="commit">确定修改</button>
        </div>
    </form>
</body>
<script>
    layui.use(['table', 'jquery', 'form'], function () {
        var table = layui.table;
        var $ = layui.jquery;
        var form = layui.form;
        //自定义验证规则
        //自定义验证规则
        form.verify({
            pass: [
                /^[\S]{6,12}$/
                ,'密码必须6到12位，且不能出现空格'
            ]
        });
        //校验输入的新密码要跟再次输入的密码一样
        $("#form #again_password").blur(function () {
            if ($("#new_password").val() != $("#again_password").val()) {
                layer.msg("两次输入的密码不一样", {icon: 5})
            }
        })


        $("#commit").click(function () {
            if ($("#new_password").val() != $("#again_password").val()) {
                layer.msg("两次输入的密码不一样", {icon: 5})
            }else {
                $.ajax({
                    url: '${pageContext.request.contextPath}/login/changepwd',
                    data: {e_password: $("#e_password").val(), new_password: $("#new_password").val()},
                    dataType: "json",
                    type: 'post',
                    success: function (resObj) {
                        if (resObj.code == 1) {
                            layer.msg(resObj.msg, {icon: 1})
                        } else {
                            layer.msg(resObj.msg, {icon: 5})
                        }
                    }
                })
            }

        })
    })

</script>
</html>
